package mao.leetcode.others.leetcode121;

public class Solution{

    public int maxProfit(int[] prices) {
        if (prices.length <= 1) return 0;
        int maxProfit = Integer.MIN_VALUE;
        int minPrice = prices[0];
        for (int i = 0; i < prices.length; i++) {
           if (prices[i] < minPrice)
               minPrice=prices[i];
           if (prices[i]-minPrice>maxProfit)
               maxProfit=prices[i]-minPrice;
        }
        return maxProfit;
    }
}
